package students_files_test01;

public class PlainTextSalesFormatter implements SalesFormatter{
    private static PlainTextSalesFormatter singletonInstance = new PlainTextSalesFormatter();

    static public PlainTextSalesFormatter getSingletonInstance(){
        return singletonInstance;
    }

    private PlainTextSalesFormatter(){

    }

    @Override
    public String formatSales(Sales sales) {
        int i = 0;
        StringBuilder stringBuilder = new StringBuilder();
        for (Order order : sales){
            double d = 0;
            i++;
            stringBuilder.append("------------------------" + "\n" + "Order " + i + "\n\n");
            for (OrderItem orderItem : order){
                stringBuilder.append(orderItem.getQuantity() + " " + orderItem.getProduct().getCode() + " " + orderItem.getProduct().getPrice() + "\n");
                d += orderItem.getValue();
            }
            stringBuilder.append("\n" + "Total = " + d + "\n");
        }
        String s = stringBuilder.toString();
        return s;
    }

}
